module('lgx.strbuf', package.seeall)

mt = {}
mt.__index = mt

function new(s)
	o = {s or nil}
	setmetatable(o,mt)
	return o
end

function mt:__add(o)
    if not o then return self end
    if type(o) == 'string' then
        table.insert(self, o)
    elseif type(o) == 'table' then
        for i=1,#o do
            table.insert(self, table.remove(o, 1))
        end
    else
        error(string.format('strbuf.__add only support "string" and "table", but get a "%s".', type(o)), 2)
    end
	return self
end

function mt:__tostring()
	return self:concat() or ''
end

function mt:concat(sep, i, j)
	return table.concat(self, sep, i, j)
end

